package mc.util;

import java.util.Enumeration;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

public class MedcenterRequestUtil {

	public static String[] requestNames={"add","del","save", "edit"};
	public static final int ADD=0;
	public static final int DEL=1;
	public static final int SAVE=2;
	public static final int EDIT=3;
	public static final int INNE=4;
	
	//public static enum erequestNames={"add","del","save", "edit"};

	/**
	 * Metoda zwraca <code>HashMap</code> z kluczami:
	 * <ul><li>"param" - - nazwa przycisku</li>
	 * <li>"id" - wartosc</li></ul>
	 * @param request
	 * @return
	 * @author blazej
	 */
	public static HashMap<String,Integer> checkButtonName(HttpServletRequest request){
		
		HashMap<String,Integer> h=new HashMap<String,Integer>();
		
		Enumeration e=request.getParameterNames();
		int id=-1;
		
		while(e.hasMoreElements()){
			
			String s=e.nextElement().toString();
			
			
			for(int i=0;i<requestNames.length;i++){
				if(s.startsWith(requestNames[i])){
					int p=s.indexOf(',');
					if(p>-1){
						id=Integer.valueOf(s.substring(p+1));
					}
					
					h.put("param",i);
					h.put("id", id);
					
					return h;
					
				}
			}
			
		}
		
		h.put("param",MedcenterRequestUtil.INNE);
		
		return h;
	}
	
	
	
	
	
	
	
	
	
	
	
	
}
